package com.xm_jd.model.dao;

import java.util.List;

import com.xm_jd.model.entitys.car;
import com.xm_jd.model.entitys.tb_car;
import com.xm_jd.model.entitys.tb_shoop;
import com.xm_jd.utils.BaseDao;

public class TianDao {
		BaseDao<car> bdao = new BaseDao<>(car.class);
		
		/**�����ﳵ�����Ʒ
		 * @param sum
		 * @return  
		 */
		public int addgood(car sum){
			String sql="INSERT INTO tb_car(car_id,car_user_id,car_shoop_sid,car_gounum,car_xuanzhong) VALUES(?,?,?,?,?)";
			return bdao.executeUpdate(sql, new Object[]{sum.getCar_id(),sum.getCar_user_id(),sum.getCar_shoop_sid(),sum.getCar_gounum(),sum.getCar_xuanzhong()});
		}
		/**
		 * �����û���Ų�ѯ���ﳵ
		 * @param uid
		 * @return
		 */
		public List<car> getCartList(int uid){
			String sql="select * from tb_car inner join tb_shoop on tb_car.car_shoop_sid=tb_shoop.shoop_Id inner join tb_picture ON tb_shoop.`shoop_Id`=tb_picture.`picture_shoop_Id` where car_user_id=?  and picture_Zcg=1";
			return bdao.selectAll(sql, new Object[]{uid});
		}
		public List<car> getxuan(int uid){
			String sql="select * from tb_car inner join tb_shoop on tb_car.car_shoop_sid=tb_shoop.shoop_Id inner join tb_picture ON tb_shoop.`shoop_Id`=tb_picture.`picture_shoop_Id` where car_user_id=?  and picture_Zcg=1 and car_xuanzhong=1";
			return bdao.selectAll(sql, new Object[]{uid});
		}
		
		/**����id��ɾ�����ﳵ����ɾ������Ʒ
		 * @param caid
		 * @return
		 */
		public int deleteid(int caid){
			String sql="delete from tb_car where car_id=?";
			return bdao.executeUpdate(sql, new Object[]{caid});
		}
		
		/**������ť�Ӽ��ķ���
		 * @param id
		 * @return
		 */
		public int jianshu(String id){
			String sql="update tb_car set car_gounum=car_gounum-1 where car_id=?";
			return bdao.executeUpdate(sql, new Object[]{id});
		}
		
		public int jiajiashu(String id){
			String sql="update tb_car set car_gounum=car_gounum+1 where car_id=?";
			return bdao.executeUpdate(sql, new Object[]{id});
		}
		
		public List<tb_car> shangs(int sid){
			String sql="select * from tb_car where car_shoop_sid=?";
			BaseDao<tb_car> sdao=new BaseDao<>(tb_car.class);
			return sdao.selectAll(sql, new Object[]{sid});
		}
		
		public int gidduibi(int shoopid, int num){
			String sql="update tb_car set car_gounum=? where car_shoop_sid=?";
			return bdao.executeUpdate(sql, new Object[]{num,shoopid});
		}
		
		public int updatexuan(int xuan,int cid){
			String sql="update tb_car set car_xuanzhong=? where car_id=?";
			return bdao.executeUpdate(sql, new Object[]{xuan,cid});
		}
}
